﻿using UnityEngine;
using System.Collections;

public class StageObjectFight : StageObject
{
    private float time1 = 0;

    public StageObjectFight()
    {

    }

    public override void Start()
    {
        base.Start();

        // 显示控制UI
        UIManager.GetInstance().GetUI<MainUI>().Show();

        // 创建背景
        StaticObject floor = new StaticObject(this, "Floor");
        floor.SetPosition(new Vector3(0, -3, 0));
        floor.Start();

        // 创建双方防御塔
        {
            TowerObject towerObj = StageManager.Create<TowerObject>(this, 3);
            towerObj.SetPosition(new Vector3(-8, -2.2f, 0));
            towerObj.GetModule().Get<ModAttr>().SetMapHp(200);
            towerObj.GetModule().Get<ModAttr>().SetCurHp(200);
            towerObj.GetModule().Get<ModAttr>().SetGroup(ModAttr.GROUP_RED);
            towerObj.Start();
        }

        {
            TowerObject towerObj = StageManager.Create<TowerObject>(this, 4);
            towerObj.SetPosition(new Vector3(8, -2.2f, 0));
            towerObj.GetModule().Get<ModAttr>().SetMapHp(200);
            towerObj.GetModule().Get<ModAttr>().SetCurHp(200);
            towerObj.GetModule().Get<ModAttr>().SetGroup(ModAttr.GROUP_BLUE);
            towerObj.Start();
        }
    }

    public override void Destroy()
    {
        base.Destroy();

        GameUtils.ClearAllWorldObjs(this);

        UIManager.GetInstance().GetUI<MainUI>().Hide();
    }

    public override void Update(float deltaTime)
    {
        base.Update(deltaTime);

        time1 -= deltaTime;

        if (time1 < 0)
        {
            time1 = Random.Range(3, 5);

            MonsterObject boss = StageManager.Create<MonsterObject>(this, 1);
            boss.SetPosition(new Vector3(4, -2.2f, 0));
            boss.GetModule().Get<ModAttr>().SetMapHp(50);
            boss.GetModule().Get<ModAttr>().SetCurHp(50);
            boss.GetModule().Get<ModAttr>().SetSpeed(2);
            boss.GetModule().Get<ModAttr>().SetGroup(ModAttr.GROUP_BLUE);
            boss.Start();
        }
    }

    
}
